package com.asset.salesforce.controller;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.asset.salesforce.domain.DeletedLead;
import com.asset.salesforce.domain.Employee;
import com.asset.salesforce.domain.Lead;
import com.asset.salesforce.domain.Post;
import com.asset.salesforce.domain.StockCategory;
import com.asset.salesforce.domain.StockProduct;
import com.asset.salesforce.domain.StockSku;
import com.asset.salesforce.domain.StockSubCategory;
import com.asset.salesforce.domain.UpdateChatter;
import com.asset.salesforce.enums.FOLLOWTYPE;
import com.asset.salesforce.enums.UPDATETYPE;
import com.asset.salesforce.form.StockCategoryForm;
import com.asset.salesforce.form.StockProductForm;
import com.asset.salesforce.form.StockSkuForm;
import com.asset.salesforce.form.StockSubCategoryForm;
import com.asset.salesforce.service.CalendarService;
import com.asset.salesforce.service.InventoryService;
import com.asset.salesforce.service.JoinRequestService;

@Controller
public class InventoryController {

	@Autowired
	private JoinRequestService joinRequestService;
	
	@Autowired
	private InventoryService inventoryService;

	@Autowired
	private CalendarService calendarService;
	
	@RequestMapping(value="/inventory",method=RequestMethod.GET)
	public String getViews(Model model,HttpSession session,
			@RequestParam(value="viewId",required =false) Integer viewId){
			if(null ==session.getAttribute("userDetails") ){
				return "redirect:/s/login.html";
			}
				Employee userDetails = (Employee)session.getAttribute("userDetails");
				joinRequestService.getJoinRquestNo(session, model);
				calendarService.getAppointmentEventsNo(session, model);
				calendarService.getCallEventssNo(session, model);
				return "inventory";
	}
	
	@RequestMapping(value="/new-category" ,method=RequestMethod.GET)
	public String getNewCategory(Model model ,HttpSession session,HttpServletRequest request,HttpServletResponse response, ModelMap modelMap){
		if (SecurityUtils.getSubject().hasRole("stockCategoryAdd")){
		try {
			request.setCharacterEncoding("UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(null ==session.getAttribute("userDetails") ){
			return "redirect:/s/login.html";
		}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		StockCategoryForm categoryForm = new StockCategoryForm();
		modelMap.addAttribute("categoryForm", categoryForm);
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return "new-stock-category";
		}else{
			return "accessDenied";
		}
	}
	
	@RequestMapping(value="/new-stock-category" ,method=RequestMethod.POST)
	public String postNewCategory(HttpSession session,HttpServletRequest request,HttpServletResponse response,
			Model model, ModelMap modelMap,
			@Valid @ModelAttribute("categoryForm") StockCategoryForm categoryForm,BindingResult result){
		try {
			request.setCharacterEncoding("UTF-8");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		if(null ==session.getAttribute("userDetails") ){
			return "redirect:/s/login.html";
		}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		if(result.hasErrors()){
			joinRequestService.getJoinRquestNo(session, model);
			calendarService.getAppointmentEventsNo(session, model);
			calendarService.getCallEventssNo(session, model);
			model.addAttribute("categoryForm", categoryForm);
			return "new-stock-category";
		}
		StockCategory stockCategory = new StockCategory();
		Date dateCreated = new Date();
		try {
			if(categoryForm.getName() != null && !categoryForm.getName().equalsIgnoreCase("")){
				stockCategory.setName(categoryForm.getName());
			}
			if(categoryForm.getCode() != null && !categoryForm.getCode().equalsIgnoreCase("")){
				stockCategory.setCode(categoryForm.getCode());
			}
			if(categoryForm.getInfo() != null && !categoryForm.getInfo().equalsIgnoreCase("")){
				stockCategory.setInfo(categoryForm.getInfo());
			}
			if(categoryForm.getDescription() != null && !categoryForm.getDescription().equalsIgnoreCase("")){
				stockCategory.setDescription(categoryForm.getDescription());
			}
			if(categoryForm.getFeedback() != null && !categoryForm.getFeedback().equalsIgnoreCase("")){
				stockCategory.setFeedback(categoryForm.getFeedback());
			}
			if(categoryForm.getComment() != null && !categoryForm.getComment().equalsIgnoreCase("")){
				stockCategory.setComment(categoryForm.getComment());
			}
			stockCategory.setDateCreated(dateCreated);
			stockCategory.setDateModified(dateCreated);
			stockCategory.setOwner(userDetails);
			
			inventoryService.addStockCategory(stockCategory);
			
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("################# stock category ex ################");
		}
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return  "redirect:/s/inventory.html";
	}
	
	@RequestMapping(value="/new-sub-category" ,method=RequestMethod.GET)
	public String getNewSubCategory(Model model ,HttpSession session,HttpServletRequest request,HttpServletResponse response, ModelMap modelMap){
		if (SecurityUtils.getSubject().hasRole("subCategoryAdd")){
		try {
			request.setCharacterEncoding("UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(null ==session.getAttribute("userDetails") ){
			return "redirect:/s/login.html";
		}
		 if(request.getParameter("parentId") !=null){
			   Integer parentId = Integer.parseInt(request.getParameter("parentId").toString());
			   modelMap.addAttribute("parentId", parentId);
			  }
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		StockSubCategoryForm subcategoryForm = new StockSubCategoryForm();
		modelMap.addAttribute("subcategoryForm", subcategoryForm);
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return "new-sub-category";
		}else{
			return "accessDenied";
		}
	}
	
	@RequestMapping(value="/new-sub-category" ,method=RequestMethod.POST)
	public String postNewSubCategory(HttpSession session,HttpServletRequest request,HttpServletResponse response,
			Model model, ModelMap modelMap,
			@Valid @ModelAttribute("subcategoryForm") StockSubCategoryForm subcategoryForm,BindingResult result){
		try {
			request.setCharacterEncoding("UTF-8");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		if(null ==session.getAttribute("userDetails") ){
			return "redirect:/s/login.html";
		}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		StockCategory parentStock = inventoryService.getStockCategoryById(subcategoryForm.getParentId());
		modelMap.addAttribute("parentId", parentStock.getId());
		if(result.hasErrors()){
			joinRequestService.getJoinRquestNo(session, model);
			calendarService.getAppointmentEventsNo(session, model);
			calendarService.getCallEventssNo(session, model);
			model.addAttribute("subcategoryForm", subcategoryForm);
			return "new-sub-category";
		}
		StockSubCategory stockSubCategory = new StockSubCategory();
		Date dateCreated = new Date();
		try {
			if(subcategoryForm.getName() != null && !subcategoryForm.getName().equalsIgnoreCase("")){
				stockSubCategory.setName(subcategoryForm.getName());
			}
			if(subcategoryForm.getCode() != null && !subcategoryForm.getCode().equalsIgnoreCase("")){
				stockSubCategory.setCode(subcategoryForm.getCode());
			}
			if(subcategoryForm.getInfo() != null && !subcategoryForm.getInfo().equalsIgnoreCase("")){
				stockSubCategory.setInfo(subcategoryForm.getInfo());
			}
			if(subcategoryForm.getDescription() != null && !subcategoryForm.getDescription().equalsIgnoreCase("")){
				stockSubCategory.setDescription(subcategoryForm.getDescription());
			}
			if(subcategoryForm.getFeedback() != null && !subcategoryForm.getFeedback().equalsIgnoreCase("")){
			stockSubCategory.setFeedback(subcategoryForm.getFeedback());
		}
			if(subcategoryForm.getComment() != null && !subcategoryForm.getComment().equalsIgnoreCase("")){
				stockSubCategory.setComment(subcategoryForm.getComment());
			}
			if(parentStock != null){
				stockSubCategory.setStockCategory(parentStock);
			}
			stockSubCategory.setDateCreated(dateCreated);
			stockSubCategory.setDateModified(dateCreated);
			stockSubCategory.setOwner(userDetails);
			
			inventoryService.addStockSubCategory(stockSubCategory);
			
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("################# stock category ex ################");
		}
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return  "redirect:/s/inventory.html";
	}
	
	@RequestMapping(value="/new-product" ,method=RequestMethod.GET)
	public String getNewProduct(Model model ,HttpSession session,HttpServletRequest request,HttpServletResponse response, ModelMap modelMap){
		if (SecurityUtils.getSubject().hasRole("stockProductAdd")){
		try {
			request.setCharacterEncoding("UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(null ==session.getAttribute("userDetails") ){
			return "redirect:/s/login.html";
		}
		 if(request.getParameter("parentId") !=null){
			   Integer parentId = Integer.parseInt(request.getParameter("parentId").toString());
			   modelMap.addAttribute("parentId", parentId);
			  }
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		StockProductForm productcategoryForm = new StockProductForm();
		modelMap.addAttribute("productcategoryForm", productcategoryForm);
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return "new-product";
		}else{
			return "accessDenied";
		}
	}
	
	@RequestMapping(value="/new-product" ,method=RequestMethod.POST)
	public String postNewProduct(HttpSession session,HttpServletRequest request,HttpServletResponse response,
			Model model, ModelMap modelMap,
			@Valid @ModelAttribute("productcategoryForm") StockProductForm productcategoryForm,BindingResult result){
		try {
			request.setCharacterEncoding("UTF-8");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		if(null ==session.getAttribute("userDetails") ){
			return "redirect:/s/login.html";
		}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		StockSubCategory parentStock = inventoryService.getStockSubCategoryById(productcategoryForm.getParentId());
		modelMap.addAttribute("parentId", parentStock.getId());

		if(result.hasErrors()){
			joinRequestService.getJoinRquestNo(session, model);
			calendarService.getAppointmentEventsNo(session, model);
			calendarService.getCallEventssNo(session, model);
			model.addAttribute("productcategoryForm", productcategoryForm);
			return "new-product";
		}
		StockProduct stockProduct = new StockProduct();
		Date dateCreated = new Date();
		try {
			if(productcategoryForm.getName() != null && !productcategoryForm.getName().equalsIgnoreCase("")){
				stockProduct.setName(productcategoryForm.getName());
			}
			if(productcategoryForm.getCode() != null && !productcategoryForm.getCode().equalsIgnoreCase("")){
				stockProduct.setCode(productcategoryForm.getCode());
			}
			if(productcategoryForm.getInfo() != null && !productcategoryForm.getInfo().equalsIgnoreCase("")){
				stockProduct.setInfo(productcategoryForm.getInfo());
			}
			if(productcategoryForm.getDescription() != null && !productcategoryForm.getDescription().equalsIgnoreCase("")){
				stockProduct.setDescription(productcategoryForm.getDescription());
			}
			if(productcategoryForm.getFeedback() != null && !productcategoryForm.getFeedback().equalsIgnoreCase("")){
				stockProduct.setFeedback(productcategoryForm.getFeedback());
			}
			if(productcategoryForm.getComment() != null && !productcategoryForm.getComment().equalsIgnoreCase("")){
				stockProduct.setComment(productcategoryForm.getComment());
			}
			if(productcategoryForm.getQuantity() != null && !productcategoryForm.getQuantity().equalsIgnoreCase("")){
				stockProduct.setQuantity(productcategoryForm.getQuantity());
			}
			if(parentStock != null){
				stockProduct.setStockSubCategory(parentStock);
			}
			stockProduct.setDateCreated(dateCreated);
			stockProduct.setDateModified(dateCreated);
			stockProduct.setOwner(userDetails);
			
			inventoryService.addStockProduct(stockProduct);
			
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("################# stock category ex ################");
		}
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return  "redirect:/s/inventory.html";
	}
	
	@RequestMapping(value="/new-sku" ,method=RequestMethod.GET)
	public String getNewSKU(Model model ,HttpSession session,HttpServletRequest request,HttpServletResponse response, ModelMap modelMap){
		if (SecurityUtils.getSubject().hasRole("stockSKUAdd")){
		try {
			request.setCharacterEncoding("UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(null ==session.getAttribute("userDetails") ){
			return "redirect:/s/login.html";
		}
		 if(request.getParameter("parentId") !=null){
			   Integer parentId = Integer.parseInt(request.getParameter("parentId").toString());
			   modelMap.addAttribute("parentId", parentId);
			  }
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		StockSkuForm skucategoryForm = new StockSkuForm();
		modelMap.addAttribute("skucategoryForm", skucategoryForm);
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return "new-sku";
		}else{
			return "accessDenied";
		}
	}
	
	@RequestMapping(value="/new-sku" ,method=RequestMethod.POST)
	public String postNewSKU(HttpSession session,HttpServletRequest request,HttpServletResponse response,
			Model model, ModelMap modelMap,
			@Valid @ModelAttribute("skucategoryForm") StockSkuForm skucategoryForm,BindingResult result){
		try {
			request.setCharacterEncoding("UTF-8");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		if(null ==session.getAttribute("userDetails") ){
			return "redirect:/s/login.html";
		}
		System.out.println("###################" + skucategoryForm.getParentId() + "@@@@@@@@@@@@");
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		//StockProduct parentStock = inventoryService.getStockProductById(parentId);
		StockProduct parentStock = inventoryService.getStockProductById(skucategoryForm.getParentId());
		modelMap.addAttribute("parentId", parentStock.getId());

		if(result.hasErrors()){
			joinRequestService.getJoinRquestNo(session, model);
			calendarService.getAppointmentEventsNo(session, model);
			calendarService.getCallEventssNo(session, model);
			model.addAttribute("skucategoryForm", skucategoryForm);
			return "new-sku";
		}
		StockSku stockSKU = new StockSku();
		Date dateCreated = new Date();
		try {
			if(skucategoryForm.getName() != null && !skucategoryForm.getName().equalsIgnoreCase("")){
				stockSKU.setName(skucategoryForm.getName());
			}
			if(skucategoryForm.getCode() != null && !skucategoryForm.getCode().equalsIgnoreCase("")){
				stockSKU.setCode(skucategoryForm.getCode());
			}
			if(skucategoryForm.getInfo() != null && !skucategoryForm.getInfo().equalsIgnoreCase("")){
				stockSKU.setInfo(skucategoryForm.getInfo());
			}
			if(skucategoryForm.getDescription() != null && !skucategoryForm.getDescription().equalsIgnoreCase("")){
				stockSKU.setDescription(skucategoryForm.getDescription());
			}
			if(skucategoryForm.getFeedback() != null && !skucategoryForm.getFeedback().equalsIgnoreCase("")){
				stockSKU.setFeedback(skucategoryForm.getFeedback());
		}
			if(skucategoryForm.getComment() != null && !skucategoryForm.getComment().equalsIgnoreCase("")){
				stockSKU.setComment(skucategoryForm.getComment());
			}
			if(skucategoryForm.getQuantity() != null && !skucategoryForm.getQuantity().equalsIgnoreCase("")){
				stockSKU.setQuantity(skucategoryForm.getQuantity());
			}
			if(skucategoryForm.getPrice() != null && !skucategoryForm.getPrice().equalsIgnoreCase("")){
				stockSKU.setPrice(skucategoryForm.getPrice());
			}
			if(skucategoryForm.getSale() != null && !skucategoryForm.getSale().equalsIgnoreCase("")){
				stockSKU.setSale(skucategoryForm.getSale());
			}
			if(parentStock != null){
				stockSKU.setStockProduct(parentStock);
			}
			stockSKU.setDateCreated(dateCreated);
			stockSKU.setDateModified(dateCreated);
			stockSKU.setOwner(userDetails);
			
			inventoryService.addStockSku(stockSKU);
			
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("################# stock category ex ################");
		}
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return  "redirect:/s/inventory.html";
	}
	@RequestMapping(value="/stock-categories" ,method=RequestMethod.GET)
	public String getStockCategories(HttpSession session,Model model,HttpServletResponse response){
		if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		model.addAttribute("userDetails",userDetails);
		List<StockCategory> stockList = new ArrayList<StockCategory>();
		stockList = inventoryService.getAllStockCategoriesByCompanyId(userDetails);
		model.addAttribute("stockList", stockList);
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return "stock-categories";
	}
	
	@RequestMapping(value="/stock-sub-categories" ,method=RequestMethod.GET)
	public String getStockSubCategories(HttpSession session,Model model,HttpServletResponse response){
		if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		model.addAttribute("userDetails",userDetails);
		List<StockSubCategory> stockList = new ArrayList<StockSubCategory>();
		stockList = inventoryService.getAllStockSubCategoriesByCompanyId(userDetails);
		model.addAttribute("stockList", stockList);
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return "stock-sub-categories";
	}
	
	@RequestMapping(value="/stock-products" ,method=RequestMethod.GET)
	public String getStockProducts(HttpSession session,Model model,HttpServletResponse response){
		if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		model.addAttribute("userDetails",userDetails);
		List<StockProduct> stockList = new ArrayList<StockProduct>();
		stockList = inventoryService.getAllStockProductsByCompanyId(userDetails);
		model.addAttribute("stockList", stockList);
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return "stock-products";
	}
	
	@RequestMapping(value="/stock-skus" ,method=RequestMethod.GET)
	public String getStockSKUs(HttpSession session,Model model,HttpServletResponse response){
		if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		model.addAttribute("userDetails",userDetails);
		List<StockSku> stockList = new ArrayList<StockSku>();
		stockList = inventoryService.getAllStockSKUsByCompanyId(userDetails);
		model.addAttribute("stockList", stockList);
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return "stock-skus";
	}
	@RequestMapping(value="/view-stock-category" ,method=RequestMethod.GET)
	public String getStockCategory(HttpSession session,Model model,HttpServletResponse response,
			@RequestParam(value="id",required=false)Integer id){
		if (SecurityUtils.getSubject().hasRole("stockCategoryView")){
		if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		model.addAttribute("userDetails",userDetails);
		StockCategory stock = new StockCategory();
		stock = inventoryService.getStockCategoryById(id);
		model.addAttribute("stock", stock);
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return "view-stock-category";
		}else{
			return "accessDenied";
		}
	}
	
	@RequestMapping(value="/view-stock-sub-category" ,method=RequestMethod.GET)
	public String getStockSubCategory(HttpSession session,Model model,HttpServletResponse response,
			@RequestParam(value="id",required=false)Integer id){
		if (SecurityUtils.getSubject().hasRole("subCategoryView")){
		if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		model.addAttribute("userDetails",userDetails);
		StockSubCategory stock = new StockSubCategory();
		stock = inventoryService.getStockSubCategoryById(id);
		model.addAttribute("stock", stock);
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return "view-stock-sub-category";
		}else{
			return "accessDenied";
		}
	}
	
	@RequestMapping(value="/view-stock-product" ,method=RequestMethod.GET)
	public String getStockProduct(HttpSession session,Model model,HttpServletResponse response,
			@RequestParam(value="id",required=false)Integer id){
		if (SecurityUtils.getSubject().hasRole("stockProductView")){
		if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		model.addAttribute("userDetails",userDetails);
		StockProduct stock = new StockProduct();
		stock = inventoryService.getStockProductById(id);
		model.addAttribute("stock", stock);
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return "view-stock-product";
		}else{
			return "accessDenied";
		}
	}
	
	@RequestMapping(value="/view-stock-sku" ,method=RequestMethod.GET)
	public String getStockSKU(HttpSession session,Model model,HttpServletResponse response,
			@RequestParam(value="id",required=false)Integer id){
		if (SecurityUtils.getSubject().hasRole("stockSKUView")){
		if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		model.addAttribute("userDetails",userDetails);
		StockSku stock = new StockSku();
		stock = inventoryService.getStockSKUById(id);
		model.addAttribute("stock", stock);
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		return "view-stock-sku";
		}else{
			return "accessDenied";
		}
	}
	
	@RequestMapping(value="/edit-category",method=RequestMethod.GET)
	public String getEditCategory(Model model,HttpSession session,HttpServletRequest request,
			@RequestParam(value="viewId",required =false) Integer viewId){
		if (SecurityUtils.getSubject().hasRole("stockCategoryEdit")){
		if(null ==session.getAttribute("userDetails") ){
			return "redirect:/s/login.html";
		}
			Employee userDetails = (Employee)session.getAttribute("userDetails");
			joinRequestService.getJoinRquestNo(session, model);
			calendarService.getAppointmentEventsNo(session, model);
			calendarService.getCallEventssNo(session, model);
			if(request.getParameter("id").toString() != null){
				StockCategory stockCategory	= inventoryService.getStockCategoryById(Integer.parseInt(request.getParameter("id").toString()));
				StockCategoryForm stockCategoryForm = new StockCategoryForm();
				if(stockCategory.getCode() != null){
					stockCategoryForm.setCode(stockCategory.getCode());
				}
				if(stockCategory.getComment()!= null){
					stockCategoryForm.setComment(stockCategory.getComment());
				}
				if(stockCategory.getInfo() != null){
				stockCategoryForm.setInfo(stockCategory.getInfo());
				}
				if(stockCategory.getDescription() != null){
					stockCategoryForm.setDescription(stockCategory.getDescription());
				}
				if(stockCategory.getFeedback() != null){
					stockCategoryForm.setFeedback(stockCategory.getFeedback());
				}
				if(stockCategory.getFlag() != null){
					stockCategoryForm.setFlag(stockCategory.getFlag());
				}
				if(stockCategory.getName() != null){
					stockCategoryForm.setName(stockCategory.getName());
				}
				if(stockCategory.getIsDeleted() != null){
					stockCategoryForm.setIsDeleted(stockCategory.getIsDeleted());
				}
				if(stockCategory.getNumber() != null){
					stockCategoryForm.setNumber(stockCategory.getNumber());
				}
				if(stockCategory.getOwner() != null){
					stockCategoryForm.setOwner(stockCategory.getOwner());
				}	
				model.addAttribute("categoryForm", stockCategoryForm);
				model.addAttribute("id", stockCategory.getId());
			}else{
				model.addAttribute("categoryForm", new StockCategory());
				model.addAttribute("id", new Integer(0));
			}
			return "edit-category";
		}else{
			return "accessDenied";
		}
	}
	@RequestMapping(value="/edit-sub-category",method=RequestMethod.GET)
	public String getEditSubCategory(Model model,HttpSession session,HttpServletRequest request){
		if (SecurityUtils.getSubject().hasRole("subCategoryEdit")){
		if(null ==session.getAttribute("userDetails") ){
			return "redirect:/s/login.html";
		}
			Employee userDetails = (Employee)session.getAttribute("userDetails");
			joinRequestService.getJoinRquestNo(session, model);
			calendarService.getAppointmentEventsNo(session, model);
			calendarService.getCallEventssNo(session, model);
			StockSubCategory stockSubCategory	= inventoryService.getStockSubCategoryById(Integer.parseInt(request.getParameter("id").toString()));
			if(request.getParameter("id").toString() != null){
				
				StockCategoryForm stockCategoryForm = new StockCategoryForm();
				if(stockSubCategory.getCode() != null){
				stockCategoryForm.setCode(stockSubCategory.getCode());
				}
				if(stockSubCategory.getComment() != null){
				stockCategoryForm.setComment(stockSubCategory.getComment());
				}
				if(stockSubCategory.getInfo() != null){
				stockCategoryForm.setInfo(stockSubCategory.getInfo());
				}
				if(stockSubCategory.getDescription() != null){
				stockCategoryForm.setDescription(stockSubCategory.getDescription());
				}
				if(stockSubCategory.getFeedback() != null){
				stockCategoryForm.setFeedback(stockSubCategory.getFeedback());
				}
				if(stockSubCategory.getFlag() != null){
				stockCategoryForm.setFlag(stockSubCategory.getFlag());
				}
				if(stockSubCategory.getName() != null){
				stockCategoryForm.setName(stockSubCategory.getName());
				}
				if(stockSubCategory.getIsDeleted() != null){
				stockCategoryForm.setIsDeleted(stockSubCategory.getIsDeleted());
				}
				if(stockSubCategory.getNumber() != null){
				stockCategoryForm.setNumber(stockSubCategory.getNumber());
				}

				if(stockSubCategory.getOwner() != null){
					stockCategoryForm.setOwner(stockSubCategory.getOwner());
				}

				if(stockSubCategory.getStockCategory() != null){
					stockCategoryForm.setStockCategory(stockSubCategory.getStockCategory());
				}
	
				
				model.addAttribute("categoryForm", stockCategoryForm);
				model.addAttribute("id", stockSubCategory.getId());
				return "edit-sub-category";
			}else{

				model.addAttribute("categoryForm", new StockCategoryForm());
				model.addAttribute("id", stockSubCategory.getId());
				return "edit-sub-category";
			}
		}else{
			return "accessDenied";
		}
	}
	@RequestMapping(value="/edit-product",method=RequestMethod.GET)
	public String getEditProduct(Model model,HttpSession session,HttpServletRequest request){
		if (SecurityUtils.getSubject().hasRole("stockProductEdit")){
		if(null ==session.getAttribute("userDetails") ){
			return "redirect:/s/login.html";
		}
			Employee userDetails = (Employee)session.getAttribute("userDetails");
			joinRequestService.getJoinRquestNo(session, model);
			calendarService.getAppointmentEventsNo(session, model);
			calendarService.getCallEventssNo(session, model);
			StockProduct stockProduct	= inventoryService.getStockProductById(Integer.parseInt(request.getParameter("id").toString()));
			if(request.getParameter("id").toString() != null){
				
				
				StockCategoryForm stockCategoryForm = new StockCategoryForm();
				if(stockProduct.getCode() != null){
					stockCategoryForm.setCode(stockProduct.getCode());
					}
					if(stockProduct.getComment() != null){
					stockCategoryForm.setComment(stockProduct.getComment());
					}
					if(stockProduct.getInfo() != null){
						stockCategoryForm.setInfo(stockProduct.getInfo());
					}
					if(stockProduct.getDescription() != null){
					stockCategoryForm.setDescription(stockProduct.getDescription());
					}
					if(stockProduct.getFeedback() != null){
					stockCategoryForm.setFeedback(stockProduct.getFeedback());
					}
					if(stockProduct.getFlag() != null){
					stockCategoryForm.setFlag(stockProduct.getFlag());
					}
					if(stockProduct.getName() != null){
					stockCategoryForm.setName(stockProduct.getName());
					}
					if(stockProduct.getIsDeleted() != null){
					stockCategoryForm.setIsDeleted(stockProduct.getIsDeleted());
					}
					if(stockProduct.getNumber() != null){
					stockCategoryForm.setNumber(stockProduct.getNumber());
					}

					if(stockProduct.getOwner() != null){
						stockCategoryForm.setOwner(stockProduct.getOwner());
					}

					if(stockProduct.getStockSubCategory() != null){
						stockCategoryForm.setStockSubCategory(stockProduct.getStockSubCategory());
					}
					if(stockProduct.getQuantity() != null){
						stockCategoryForm.setQuantity(stockProduct.getQuantity());
					}
				model.addAttribute("categoryForm", stockCategoryForm);
				model.addAttribute("id", stockProduct.getId());
				
			}else{
				model.addAttribute("categoryForm", new StockCategoryForm());
				model.addAttribute("id", stockProduct.getId());
			}
			return "edit-product";
		}else{
			return "accessDenied";
		}
		}

@RequestMapping(value="/edit-sku",method=RequestMethod.GET)
public String getEditCategory(Model model,HttpSession session,HttpServletRequest request, ModelMap modelMap){
	if (SecurityUtils.getSubject().hasRole("stockSKUEdit")){
	if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
		Employee userDetails = (Employee)session.getAttribute("userDetails");
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		StockSku stockSku = inventoryService.getStockSKUById(Integer.parseInt(request.getParameter("id").toString()));
		if(request.getParameter("id").toString() != null){
			StockCategoryForm stockCategoryForm = new StockCategoryForm();
				if(stockSku.getCode() != null){
				stockCategoryForm.setCode(stockSku.getCode());
				}
				if(stockSku.getComment() != null){
				stockCategoryForm.setComment(stockSku.getComment());
				}
				if(stockSku.getInfo() != null){
				stockCategoryForm.setInfo(stockSku.getInfo());
				}
				if(stockSku.getDescription() != null){
				stockCategoryForm.setDescription(stockSku.getDescription());
				}
				if(stockSku.getFeedback() != null){
				stockCategoryForm.setFeedback(stockSku.getFeedback());
				}
				if(stockSku.getFlag() != null){
				stockCategoryForm.setFlag(stockSku.getFlag());
				}
				if(stockSku.getName() != null){
				stockCategoryForm.setName(stockSku.getName());
				}
				if(stockSku.getIsDeleted() != null){
				stockCategoryForm.setIsDeleted(stockSku.getIsDeleted());
				}
				if(stockSku.getNumber() != null){
				stockCategoryForm.setNumber(stockSku.getNumber());
				}

				if(stockSku.getOwner() != null){
					stockCategoryForm.setOwner(stockSku.getOwner());
				}

				if(stockSku.getStockProduct() != null){
					stockCategoryForm.setStockProduct(stockSku.getStockProduct());
				}
				if(stockSku.getQuantity() != null){
					stockCategoryForm.setQuantity(stockSku.getQuantity());
				}
				if(stockSku.getPrice() !=null){
					stockCategoryForm.setPrice(stockSku.getPrice() );
				}
				if(stockSku.getSale() != null){
					stockCategoryForm.setSale(stockSku.getSale() );
				}
				if(request.getParameter("id") !=null){
					Integer id = Integer.parseInt(request.getParameter("id").toString());
					modelMap.addAttribute("id", id);
				}
			model.addAttribute("categoryForm", stockCategoryForm);
			model.addAttribute("id", stockSku.getId());
			return "edit-sku";
			
		}else{
			model.addAttribute("categoryForm", new StockCategoryForm());
			model.addAttribute("id", stockSku.getId());
			return "edit-sku";
		}
	}else{
		return "accessDenied";
	}
}
@RequestMapping(value="/edit-category" ,method=RequestMethod.POST)
public String postEditCategory(HttpSession session,HttpServletRequest request,HttpServletResponse response,
		Model model, ModelMap modelMap,
		@Valid @ModelAttribute("categoryForm") StockCategoryForm categoryForm,BindingResult result,
		@RequestParam(value="id",required=false)Integer id){
	try {
		request.setCharacterEncoding("UTF-8");
	} catch (UnsupportedEncodingException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
	Employee userDetails = (Employee)session.getAttribute("userDetails");
	StockCategory stockCategory = inventoryService.getStockCategoryById(Integer.parseInt(request.getParameter("id").toString()));
	if(result.hasErrors()){
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		model.addAttribute("categoryForm", categoryForm);
		return "edit-category";
	}
	Date dateCreated = new Date();
	try {
		if(categoryForm.getName() != null && !categoryForm.getName().equalsIgnoreCase("")){
			stockCategory.setName(categoryForm.getName());
		}
		if(categoryForm.getCode() != null && !categoryForm.getCode().equalsIgnoreCase("")){
			stockCategory.setCode(categoryForm.getCode());
		}
		if(categoryForm.getInfo() != null && !categoryForm.getInfo().equalsIgnoreCase("")){
			stockCategory.setInfo(categoryForm.getInfo());
		}
		if(categoryForm.getDescription() != null && !categoryForm.getDescription().equalsIgnoreCase("")){
			stockCategory.setDescription(categoryForm.getDescription());
		}
		if(categoryForm.getFeedback() != null && !categoryForm.getFeedback().equalsIgnoreCase("")){
			stockCategory.setFeedback(categoryForm.getFeedback());
		}
		if(categoryForm.getComment() != null && !categoryForm.getComment().equalsIgnoreCase("")){
			stockCategory.setComment(categoryForm.getComment());
		}
		stockCategory.setDateModified(dateCreated);
		
		inventoryService.editStockCategory(stockCategory);
		
	} catch (Exception e) {
		// TODO: handle exception
		System.out.println("################# stock category ex ################");
	}
	joinRequestService.getJoinRquestNo(session, model);
	calendarService.getAppointmentEventsNo(session, model);
	calendarService.getCallEventssNo(session, model);
	return  "redirect:/s/inventory.html";
}

@RequestMapping(value="/edit-sub-category" ,method=RequestMethod.POST)
public String postEditSubCategory(HttpSession session,HttpServletRequest request,HttpServletResponse response,
		Model model, ModelMap modelMap,
		@Valid @ModelAttribute("categoryForm") StockCategoryForm categoryForm,BindingResult result,
		@RequestParam(value="id",required=false)Integer id){
	try {
		request.setCharacterEncoding("UTF-8");
	} catch (UnsupportedEncodingException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
	Employee userDetails = (Employee)session.getAttribute("userDetails");
	StockSubCategory stockSubCategory = inventoryService.getStockSubCategoryById(Integer.parseInt(request.getParameter("id").toString()));
	if(result.hasErrors()){
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		model.addAttribute("categoryForm", categoryForm);
		return "edit-sub-category";
	}
	Date dateCreated = new Date();
	try {
		if(categoryForm.getName() != null && !categoryForm.getName().equalsIgnoreCase("")){
			stockSubCategory.setName(categoryForm.getName());
		}
		if(categoryForm.getCode() != null && !categoryForm.getCode().equalsIgnoreCase("")){
			stockSubCategory.setCode(categoryForm.getCode());
		}
		if(categoryForm.getInfo() != null && !categoryForm.getInfo().equalsIgnoreCase("")){
			stockSubCategory.setInfo(categoryForm.getInfo());
		}
		if(categoryForm.getDescription() != null && !categoryForm.getDescription().equalsIgnoreCase("")){
			stockSubCategory.setDescription(categoryForm.getDescription());
		}
		if(categoryForm.getFeedback() != null && !categoryForm.getFeedback().equalsIgnoreCase("")){
			stockSubCategory.setFeedback(categoryForm.getFeedback());
		}
		if(categoryForm.getComment() != null && !categoryForm.getComment().equalsIgnoreCase("")){
			stockSubCategory.setComment(categoryForm.getComment());
		}
		stockSubCategory.setDateModified(dateCreated);
		
		inventoryService.editStockSubCategory(stockSubCategory);
		
	} catch (Exception e) {
		// TODO: handle exception
		System.out.println("################# stock category ex ################");
	}
	joinRequestService.getJoinRquestNo(session, model);
	calendarService.getAppointmentEventsNo(session, model);
	calendarService.getCallEventssNo(session, model);
	return  "redirect:/s/inventory.html";
}

@RequestMapping(value="/edit-product" ,method=RequestMethod.POST)
public String postEditProduct(HttpSession session,HttpServletRequest request,HttpServletResponse response,
		Model model, ModelMap modelMap,
		@Valid @ModelAttribute("categoryForm") StockCategoryForm categoryForm,BindingResult result,
		@RequestParam(value="id",required=false)Integer id){
	try {
		request.setCharacterEncoding("UTF-8");
	} catch (UnsupportedEncodingException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
	Employee userDetails = (Employee)session.getAttribute("userDetails");
	StockProduct stockProduct = inventoryService.getStockProductById(Integer.parseInt(request.getParameter("id").toString()));
	if(result.hasErrors()){
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		model.addAttribute("categoryForm", categoryForm);
		return "edit-product";
	}
	Date dateCreated = new Date();
	try {
		if(categoryForm.getName() != null && !categoryForm.getName().equalsIgnoreCase("")){
			stockProduct.setName(categoryForm.getName());
		}
		if(categoryForm.getCode() != null && !categoryForm.getCode().equalsIgnoreCase("")){
			stockProduct.setCode(categoryForm.getCode());
		}
		if(categoryForm.getInfo() != null && !categoryForm.getInfo().equalsIgnoreCase("")){
			stockProduct.setInfo(categoryForm.getInfo());
		}
		if(categoryForm.getDescription() != null && !categoryForm.getDescription().equalsIgnoreCase("")){
			stockProduct.setDescription(categoryForm.getDescription());
		}
		if(categoryForm.getFeedback() != null && !categoryForm.getFeedback().equalsIgnoreCase("")){
			stockProduct.setFeedback(categoryForm.getFeedback());
		}
		if(categoryForm.getComment() != null && !categoryForm.getComment().equalsIgnoreCase("")){
			stockProduct.setComment(categoryForm.getComment());
		}
		if(categoryForm.getQuantity() != null && !categoryForm.getQuantity().equalsIgnoreCase("")){
			stockProduct.setQuantity(categoryForm.getQuantity());
		}
		stockProduct.setDateModified(dateCreated);
		
		inventoryService.editStockProduct(stockProduct);
		
	} catch (Exception e) {
		// TODO: handle exception
		System.out.println("################# stock category ex ################");
	}
	joinRequestService.getJoinRquestNo(session, model);
	calendarService.getAppointmentEventsNo(session, model);
	calendarService.getCallEventssNo(session, model);
	return  "redirect:/s/inventory.html";
}

@RequestMapping(value="/edit-sku" ,method=RequestMethod.POST)
public String postEditSKU(HttpSession session,HttpServletRequest request,HttpServletResponse response,
		Model model, ModelMap modelMap,
		@Valid @ModelAttribute("categoryForm") StockCategoryForm categoryForm,BindingResult result,
		@RequestParam(value="id",required=false)Integer id){
	try {
		request.setCharacterEncoding("UTF-8");
	} catch (UnsupportedEncodingException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
	Employee userDetails = (Employee)session.getAttribute("userDetails");
	StockSku stockSKU = inventoryService.getStockSKUById(Integer.parseInt(request.getParameter("id").toString()));
	if(result.hasErrors()){
		joinRequestService.getJoinRquestNo(session, model);
		calendarService.getAppointmentEventsNo(session, model);
		calendarService.getCallEventssNo(session, model);
		model.addAttribute("categoryForm", categoryForm);
		return "edit-sku";
	}
	Date dateCreated = new Date();
	try {
		if(categoryForm.getName() != null && !categoryForm.getName().equalsIgnoreCase("")){
			stockSKU.setName(categoryForm.getName());
		}
		if(categoryForm.getCode() != null && !categoryForm.getCode().equalsIgnoreCase("")){
			stockSKU.setCode(categoryForm.getCode());
		}
		if(categoryForm.getInfo() != null && !categoryForm.getInfo().equalsIgnoreCase("")){
			stockSKU.setInfo(categoryForm.getInfo());
		}
		if(categoryForm.getDescription() != null && !categoryForm.getDescription().equalsIgnoreCase("")){
			stockSKU.setDescription(categoryForm.getDescription());
		}
		if(categoryForm.getFeedback() != null && !categoryForm.getFeedback().equalsIgnoreCase("")){
			stockSKU.setFeedback(categoryForm.getFeedback());
		}
		if(categoryForm.getComment() != null && !categoryForm.getComment().equalsIgnoreCase("")){
			stockSKU.setComment(categoryForm.getComment());
		}
		if(categoryForm.getQuantity() != null && !categoryForm.getQuantity().equalsIgnoreCase("")){
			stockSKU.setQuantity(categoryForm.getQuantity());
		}
		if(categoryForm.getPrice() != null && !categoryForm.getPrice().equalsIgnoreCase("")){
			stockSKU.setPrice(categoryForm.getPrice());
		}
		if(categoryForm.getSale() != null && !categoryForm.getSale().equalsIgnoreCase("")){
			stockSKU.setSale(categoryForm.getSale());
		}
		stockSKU.setDateModified(dateCreated);
		
		inventoryService.editStockSKU(stockSKU);
		
	} catch (Exception e) {
		// TODO: handle exception
		System.out.println("################# stock category ex ################");
	}
	joinRequestService.getJoinRquestNo(session, model);
	calendarService.getAppointmentEventsNo(session, model);
	calendarService.getCallEventssNo(session, model);
	return  "redirect:/s/inventory.html";
}

@RequestMapping(value="/delete-stock-category" ,method=RequestMethod.GET)
public String deleteCategory(HttpSession session,Model model,HttpServletRequest request,HttpServletResponse response){
	if (SecurityUtils.getSubject().hasRole("stockCategoryDelete")){
	try {
		request.setCharacterEncoding("UTF-8");
//		response.setCharacterEncoding("UTF-8");
	} catch (UnsupportedEncodingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	Employee userDetails=(Employee)session.getAttribute("userDetails");
	if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
	
	StockCategory category = inventoryService.getStockCategoryById(Integer.parseInt(request.getParameter("id")));
	inventoryService.deleteStockCategory(category);
		    model.addAttribute("userDetails",userDetails);
		    joinRequestService.getJoinRquestNo(session, model);
		    calendarService.getAppointmentEventsNo(session, model);
		    calendarService.getCallEventssNo(session, model);
		return "redirect:/s/inventory.html";
	}
	else{
		return "accessDenied";
	}
}

@RequestMapping(value="/delete-sub-category" ,method=RequestMethod.GET)
public String deleteSubCategory(HttpSession session,Model model,HttpServletRequest request,HttpServletResponse response){
	if (SecurityUtils.getSubject().hasRole("subCategoryDelete")){
	try {
		request.setCharacterEncoding("UTF-8");
//		response.setCharacterEncoding("UTF-8");
	} catch (UnsupportedEncodingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	Employee userDetails=(Employee)session.getAttribute("userDetails");
	if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
	StockSubCategory stockSubCategory = inventoryService.getStockSubCategoryById(Integer.parseInt(request.getParameter("id")));
	inventoryService.deleteStockSubCategory(stockSubCategory);
		    model.addAttribute("userDetails",userDetails);
		    joinRequestService.getJoinRquestNo(session, model);
		    calendarService.getAppointmentEventsNo(session, model);
		    calendarService.getCallEventssNo(session, model);
		return "redirect:/s/inventory.html";
	}else{
		return "accessDenied";
	}
}

@RequestMapping(value="/delete-product" ,method=RequestMethod.GET)
public String deleteProduct(HttpSession session,Model model,HttpServletRequest request,HttpServletResponse response){
	if (SecurityUtils.getSubject().hasRole("stockProductDelete")){
	try {
		request.setCharacterEncoding("UTF-8");
//		response.setCharacterEncoding("UTF-8");
	} catch (UnsupportedEncodingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	Employee userDetails=(Employee)session.getAttribute("userDetails");
	if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
	StockProduct product = inventoryService.getProductsById(Integer.parseInt(request.getParameter("id")));
	inventoryService.deleteStockProduct(product);
		    model.addAttribute("userDetails",userDetails);
		    joinRequestService.getJoinRquestNo(session, model);
		    calendarService.getAppointmentEventsNo(session, model);
		    calendarService.getCallEventssNo(session, model);
		return "redirect:/s/inventory.html";
	}else{
		return "accessDenied";
	}
}

@RequestMapping(value="/delete-sku" ,method=RequestMethod.GET)
public String deleteSKU(HttpSession session,Model model,HttpServletRequest request,HttpServletResponse response){
	if (SecurityUtils.getSubject().hasRole("stockSKUDelete")){
	try {
		request.setCharacterEncoding("UTF-8");
//		response.setCharacterEncoding("UTF-8");
	} catch (UnsupportedEncodingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	Employee userDetails=(Employee)session.getAttribute("userDetails");
	if(null ==session.getAttribute("userDetails") ){
		return "redirect:/s/login.html";
	}
	StockSku sku = inventoryService.getStockSKUById(Integer.parseInt(request.getParameter("id")));
	inventoryService.deleteStockSKU(sku);
		    model.addAttribute("userDetails",userDetails);
		    joinRequestService.getJoinRquestNo(session, model);
		    calendarService.getAppointmentEventsNo(session, model);
		    calendarService.getCallEventssNo(session, model);
		return "redirect:/s/inventory.html";
	}
	else{
		return "accessDenied";
	}
}





	
	
}
